#ifndef _OBD_H_
#define _OBD_H_

// Error Defines

#define OK 		0
#define OVERFLOW	-1	
#define BAD_DATA	-2
#define NO_DEVICE_FOUND	-3
#define IMP_DATA	-4

// OBD Defines

#define COMMAND_END	0x0D
#define RESPONSE_END	0x3E

/****************************************************************
* 		  OBD INITIALIZATION FUNCTIONS
****************************************************************/

int elm_init();
/*
*	Purpose: Initialize ELM and check that communication is correct
*	Input: Nothing
*	Output:	Returns OK or corresponding error codes
*/

int obd_init();
/*
* 	Purpose: Initialize OBDII port and check that communication is correct
* 	Input: Nothing
* 	Output: Returns OK or corresponding error codes
*/

/****************************************************************
* 		  USART OBD FUNCTIONS
****************************************************************/

void obd_transmit(unsigned char data);
/*
*	Purpose: Transmit data to the LCD
*	Input: Data to be transmitted
*	Output:	Nothing
*/

unsigned char obd_receive();
/*
*	Purpose: Receive data from the LCD
*	Input: Nothing
*	Output:	Data received	
*/

void obd_flush();
/*
*	Purpose: Receive data from the LCD
*	Input: Nothing
*	Output:	Nothing	
*/

int obd_sendcmd(unsigned char *in, unsigned char *out, char len_in);
/*
*	Purpose: Send a command to ELM to run
*	Input:	in 	- Command buffer		
*		out 	- Location to output results
*		len_in 	- Length of the input
*	Output: Returns OK or corresponding error codes
*/		

/****************************************************************
* 			USER OBD FUNCTIONS
****************************************************************/

int check_data(unsigned char *in, unsigned char *exp, int len_exp);
/*
*	Purpose: Check to make sure the data is as expected
*	Input:	in 	- Response from the ELM/OBDII
*		exp	- Expected response
*		len_exp	- Length of expected response
*	Output: Returns OK or corresponding error codes
*/

int record_data(unsigned char *in, unsigned char *out, int offset, int len_in);
/*
*	Purpose: To record the desired data from the string
*	Input: 	in 	- buffer getting data from
*		out 	- buffer outputing data to  
*		offset 	- offset from the input buffer where data begins
*		len_in	- length of input buffer
*	Output: Returns OK or corresponding error codes
*/

int get_mph();
/*
*    Purpose: Get MPH Data and Output it
*    Input: Nothing
*    Output: Mph of the vehicle or an error code, refer to error codes for their meaning
*/

int get_rpm();
/*
*    Purpose: Get RPM Data and Output it
*    Input: Nothing
*    Output: Outputs the rpm of the car or an error code, refer to error codes for their meaning
*/

#endif
